<?php
	include('connectDB.php');
	$display=20;
	if(isset($_GET['page'])&& int($_GET['page']))
	{
		$page=$_GET['page'];
	}else
	{
		$qery="select count(maphong) from phong";
		$rs=mysql_query($qery);
		$rows=mysql_fetch_array($rs, MYSQL_NUM);
		$record=$rows[0];
		if($record>$display)
		{
			$page=ceil($record/$display);
		}else { $page=1;}
	}
	$start=(isset ($_GET['start']) && (int)$_GET['start']) ? $_GET['start']:0;
?>
    <div class="title">Quản Lý Phòng</div> 
       <div class="timkiem" align="left">
      		<form action="./?mod=phong&do=timkiem" name="timkiem" method="post">
        		<label>
          		<input name="keyword" type="text"  placeholder="--Tìm Kiếm--" />
        		</label> 
       			<label>
         		<input type="submit" name="Submit" value="Tìm"/>
       		 </label>
      		</form>
      </div>   
     <div class="add" align="left"> <a href="./?mod=phong&do=add" class="button">Thêm mới phòng </a>  </div>     
      <?php
	  	$sql_getall="select * from phong order by maphong limit $start,$display";
		$r=mysql_query($sql_getall);
		
	  ?>                 
                    <div class="tbphong">
                    	<table border="1" cellpadding="0" cellspacing="0" 
                        style="font-size:12px; font-family:Arial, Helvetica, sans-serif;">
                        <tbody>
                        <tr><th>STT</th><th>Mã Phòng</th><th>Loại Phòng</th><th align="center">Dãy Nhà</th>
                        <th >Số SV</th><th>Tầng</th><th colspan="2">Action</th></tr>                     
                      <?php
				 	$i=0;
					
					while($nr=mysql_fetch_array($r, MYSQL_ASSOC))
					{
						
						$i++;
						if ($i%2==0)
						{
							
				 ?>                 
                <tr style="background:#FFC;">
                	<td> <?php echo $i;?></td>
                    <td class="style1" >
                    <a href='./?mod=phong&do=dsphong&pro_ID=<?php echo $nr['maphong'];?>'><?php echo $nr['maphong']; ?></a></td>
                    <td ><?php echo $nr['loaiphong'];?></td>
                    <td><?php echo $nr['daynha'];?></td>                    
                    <td><?php echo $nr['sosinhvien'];?></td>
                    <td><?php echo $nr['tang'];?></td>                            
                    <td><a href='./?mod=phong&do=edit&p_ID=<?php echo $nr['maphong'] ?>'>Sửa</a></td>       
                    <td ><a href='./?mod=phong&do=delete&p_ID=<?php echo $nr['maphong'] ?>'>Xóa</a></td>
                </tr>
               
               <?php }else
			   			{
							?>
				<tr style=" background:#CCC;">
                   <td> <?php echo $i;?></td>
                    <td class="style1" >
                    <a href='./?mod=phong&do=dsphong&pro_ID=<?php echo $nr['maphong'];?>'><?php echo $nr['maphong']; ?></a></td>
                    <td ><?php echo $nr['loaiphong'];?></td>
                    <td><?php echo $nr['daynha'];?></td>                    
                    <td><?php echo $nr['sosinhvien'];?></td>
                    <td><?php echo $nr['tang'];?></td>                            
                    <td><a href='./?mod=phong&do=edit&p_ID=<?php echo $nr['maphong'] ?>'>Sửa</a></td>       
                    <td ><a href='./?mod=phong&do=delete&p_ID=<?php echo $nr['maphong'] ?>'>Xóa</a></td>
                </tr>
                <?php
						}
			   			
					}
					?>
              </tbody>
           </table>                	                     						
                    </div> 
                    <ul class="pag">
                    	<?php
							if($page>1)
							{
								$next=$start + $display;
								$prov=$start-$display;
								$curren=$start/$display+1;
								if($curren !=1)
								{
								echo "<a href='./?mod=phong&do=dsphong&start=$prov'>Về đầu</a>";
								}
								for($i=1;$i<$page;$i++)
								{
									echo "|<a href='./?mod=phong&do=dsphong&start=$display*($i-1)'>$i</a>|";
								}
								if($curren !=$page)
								{
									echo "<a href='./?mod=phong&do=dsphong&start=$next'>Trang tiếp</a>";
								}
							}
							
						?>
                    </ul>
             